const int rLedPin = 6; //引脚R
const int gLedPin = 5; //引脚G
const int bLedPin = 3; //引脚B


int ledR  = 255; //R Led 亮度
int ledG  = 255; //G Led 亮度
int ledB  = 255; //B Led 亮度

void setup() {
  pinMode(rLedPin, OUTPUT);
  pinMode(gLedPin, OUTPUT);
  pinMode(bLedPin, OUTPUT);
  analogWrite(rLedPin, ledR);
  delay(100);
  analogWrite(gLedPin, ledG);
  delay(100);
  analogWrite(bLedPin, ledB); 
  delay(100); 
  Serial.begin(9600);
  Serial.println("Welcome to Taichi-Maker RGB Led Tutorial.");
  Serial.println("Please Input RGB value(eg. r128g100b20).");
}

void loop() {
  ledR = 255;
  ledG = 255;
  ledB = 0;
  serialCmd();
  delay(500);
  ximieLed();
  delay(500);

  ledR = 255;
  ledG = 0;
  ledB = 255;
  serialCmd();
  delay(500);
  ximieLed();
  delay(500);

  ledR = 0;
  ledG = 255;
  ledB = 255;
  serialCmd();
  delay(500);
  ximieLed();
  delay(500);
}

void ximieLed() {
  ledR = 255;
  ledG = 255;
  ledB = 255;
  serialCmd();
}
void serialCmd() {
  analogWrite(rLedPin, ledR);
  delay(10);
  analogWrite(gLedPin, ledG);
  delay(10);
  analogWrite(bLedPin, ledB); 
  delay(10); 
  
  Serial.print ("Red Value = ");
  Serial.println (ledR);
  Serial.print ("Green Value = ");
  Serial.println (ledG);
  Serial.print ("Blue Value = ");
  Serial.println (ledB);
  Serial.println ("-------------");    
}
